const jwt = require("jsonwebtoken");
const str = "jhjfhgsdjgjksdghjfk"; //用于签名
//创建token
function createToken(obj) {
  obj.time = Date.now();
  return jwt.sign(obj, str, { expiresIn: 60 * 60 * 2 }); //2小时
}
//验证token
function checkToken(token) {
  return new Promise((resolve, reject) => {
    jwt.verify(token, str, (err, data) => {
      if (err) {
        reject(err);
      }
      resolve(data);
    });
  });
}
module.exports = {
  createToken,
  checkToken,
};
